﻿<common:LayoutAwarePage
    x:Name="pageRoot"
    x:Class="Expenses.Views.ExpenseReportsPage"
    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
    IsTabStop="false"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Expenses.Views"
    xmlns:common="using:Expenses.Common"
    xmlns:converters="using:Expenses.Converters" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Page.Resources>
        <CollectionViewSource x:Name="ExpenseReportsViewSource"/>

        <converters:DateTimeToStringConverter x:Key="DateTimeToStringConverter"/>
        <converters:DateTimeToDaysOldStringConverter x:Key="DateTimeToDaysOldStringConverter"/>
        <converters:DoubleToCurrencyStringConverter x:Key="DoubleToCurrencyStringConverter"/>

        <DataTemplate x:Key="SavedExpenseReportTemplate">
            <StackPanel Background="{StaticResource ItemTemplateBackgroundColor}"
                        Height="150"
                        Width="325"
                        HorizontalAlignment="Left" 
                        VerticalAlignment="Top">
                <TextBlock Text="{Binding Purpose}" 
                           Margin="20,15,0,0"
                           FontSize="22" 
                           HorizontalAlignment="Left" 
                           VerticalAlignment="Center" />
                <TextBlock Text="{Binding Amount, Converter={StaticResource DoubleToCurrencyStringConverter}}" 
                           Margin="20,20,0,0"
                           FontSize="22" 
                           FontWeight="Bold" 
                           HorizontalAlignment="Left" 
                           VerticalAlignment="Center" />
                <StackPanel Orientation="Horizontal"
                            Margin="20,20,0,0">
                    <TextBlock Text="Saved on"
                               FontSize="20" 
                               HorizontalAlignment="Left" 
                               VerticalAlignment="Center" />
                    <TextBlock Text="{Binding DateSaved, Converter={StaticResource DateTimeToStringConverter}}" 
                               Margin="5,0,0,0" 
                               FontSize="20" 
                               HorizontalAlignment="Left" 
                               VerticalAlignment="Center" />
                </StackPanel>
            </StackPanel>
        </DataTemplate>

        <DataTemplate x:Key="SnappedSavedExpenseReportTemplate">
            <StackPanel Background="{StaticResource ItemTemplateBackgroundColor}"
                        Height="150"
                        Width="260"
                        HorizontalAlignment="Left" 
                        VerticalAlignment="Top">
                <TextBlock Text="{Binding Purpose}" 
                           Margin="10,15,0,0"
                           FontSize="18" 
                           HorizontalAlignment="Left" 
                           VerticalAlignment="Center" />
                <TextBlock Text="{Binding Amount, Converter={StaticResource DoubleToCurrencyStringConverter}}" 
                           Margin="10,20,0,0"
                           FontSize="18" 
                           FontWeight="Bold" 
                           HorizontalAlignment="Left" 
                           VerticalAlignment="Center" />
                <StackPanel Orientation="Horizontal"
                            Margin="10,20,0,0">
                    <TextBlock Text="Saved on"
                               FontSize="18" 
                               HorizontalAlignment="Left" 
                               VerticalAlignment="Center" />
                    <TextBlock Text="{Binding DateSaved, Converter={StaticResource DateTimeToStringConverter}}" 
                               Margin="5,0,0,0" 
                               FontSize="18" 
                               HorizontalAlignment="Left" 
                               VerticalAlignment="Center" />
                </StackPanel>
            </StackPanel>
        </DataTemplate>

        <DataTemplate x:Key="PendingExpenseReportTemplate">
            <Grid Background="{StaticResource ItemTemplateBackgroundColor}"
                  Height="200">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="125"/>
                    <ColumnDefinition Width="300"/>
                </Grid.ColumnDefinitions>
                <Grid Grid.Column="0" 
                      Margin="10,5,0,5">
                    <StackPanel HorizontalAlignment="Left" 
                                VerticalAlignment="Top">
                        <TextBlock Text="{Binding DateSubmitted, Converter={StaticResource DateTimeToDaysOldStringConverter}}" 
                                   FontSize="36" 
                                   FontWeight="Bold" 
                                   FontFamily="{StaticResource FontFamilyTitle}"
                                   HorizontalAlignment="Left" 
                                   VerticalAlignment="Top" 
                                   Margin="0,0,0,0" />
                        <TextBlock Text="day(s) old" 
                                   FontSize="18" 
                                   HorizontalAlignment="Left" 
                                   VerticalAlignment="Top" />
                    </StackPanel>
                </Grid>
                <Grid Grid.Column="1" 
                      Margin="0,5,10,10">
                    <StackPanel HorizontalAlignment="Left" 
                                VerticalAlignment="Top">
                        <TextBlock Text="{Binding Purpose}" 
                                   FontSize="22" 
                                   TextWrapping="Wrap"
                                   HorizontalAlignment="Left" 
                                   VerticalAlignment="Center" />
                        <TextBlock Text="{Binding Amount, Converter={StaticResource DoubleToCurrencyStringConverter}}" 
                                   FontSize="22" 
                                   FontWeight="Bold" 
                                   Margin="0,10,0,0"
                                   HorizontalAlignment="Left" 
                                   VerticalAlignment="Center" />
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="Submitted on " 
                                       FontSize="20" 
                                       Margin="0,10,0,0" 
                                       HorizontalAlignment="Left" 
                                       VerticalAlignment="Center" />
                            <TextBlock Text="{Binding DateSubmitted, Converter={StaticResource DateTimeToStringConverter}}" 
                                       FontSize="20" 
                                       Margin="10,10,0,0" 
                                       HorizontalAlignment="Left" 
                                       VerticalAlignment="Center" />
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding OwedToEmployee, Converter={StaticResource DoubleToCurrencyStringConverter}}" 
                                       FontSize="20" 
                                       Margin="0,10,0,0"
                                       HorizontalAlignment="Left" 
                                       VerticalAlignment="Center" />
                            <TextBlock Text="owed to employee" 
                                       FontSize="20" 
                                       Margin="10,10,0,0" 
                                       HorizontalAlignment="Left" 
                                       VerticalAlignment="Center" />
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding OwedToCreditCard, Converter={StaticResource DoubleToCurrencyStringConverter}}" 
                                       FontSize="20" 
                                       Margin="0,10,0,0"
                                       HorizontalAlignment="Left" 
                                       VerticalAlignment="Center" />
                            <TextBlock Text="owed to credit card" 
                                       FontSize="20" 
                                       Margin="10,10,0,0" 
                                       HorizontalAlignment="Left" 
                                       VerticalAlignment="Center" />
                        </StackPanel>
                    </StackPanel>
                </Grid>
            </Grid>
        </DataTemplate>

        <DataTemplate x:Key="SnappedPendingExpenseReportTemplate">
            <Grid Background="{StaticResource ItemTemplateBackgroundColor}"
                  Height="150">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="100"/>
                    <ColumnDefinition Width="160"/>
                </Grid.ColumnDefinitions>
                <Grid Grid.Column="0" 
                      Margin="10,5,0,5">
                    <StackPanel HorizontalAlignment="Left" 
                                VerticalAlignment="Top">
                        <TextBlock Text="{Binding DateSubmitted, Converter={StaticResource DateTimeToDaysOldStringConverter}}" 
                                   FontSize="28" 
                                   FontWeight="Bold" 
                                   FontFamily="{StaticResource FontFamilyTitle}"
                                   HorizontalAlignment="Left" 
                                   VerticalAlignment="Top" 
                                   Margin="0,0,0,0" />
                        <TextBlock Text="day(s) old" 
                                   FontSize="16" 
                                   HorizontalAlignment="Left" 
                                   VerticalAlignment="Top" />
                    </StackPanel>
                </Grid>
                <Grid Grid.Column="1" 
                      Margin="0,5,10,10">
                    <StackPanel HorizontalAlignment="Left" 
                                VerticalAlignment="Top">
                        <TextBlock Text="{Binding Purpose}" 
                                   FontSize="18" 
                                   TextWrapping="Wrap"
                                   HorizontalAlignment="Left" 
                                   VerticalAlignment="Center" />
                        <TextBlock Text="{Binding Amount, Converter={StaticResource DoubleToCurrencyStringConverter}}" 
                                   FontSize="18" 
                                   FontWeight="Bold" 
                                   Margin="0,10,0,0"
                                   HorizontalAlignment="Left" 
                                   VerticalAlignment="Center" />
                        <TextBlock Text="{Binding DateSubmitted, Converter={StaticResource DateTimeToStringConverter}}" 
                                   FontSize="18" 
                                   Margin="0,10,0,0" 
                                   HorizontalAlignment="Left" 
                                   VerticalAlignment="Center" />
                    </StackPanel>
                </Grid>
            </Grid>
        </DataTemplate>

        <DataTemplate x:Key="NeedingApprovalExpenseReportTemplate">
            <Grid Background="{StaticResource ItemTemplateBackgroundColor}"
                  Height="175">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="125"/>
                    <ColumnDefinition Width="200"/>
                </Grid.ColumnDefinitions>
                <Grid Grid.Column="0" 
                      Margin="10,5,0,5">
                    <StackPanel HorizontalAlignment="Left" 
                                VerticalAlignment="Top">
                        <TextBlock Text="{Binding DateSubmitted, Converter={StaticResource DateTimeToDaysOldStringConverter}}" 
                                   FontSize="36" 
                                   FontWeight="Bold" 
                                   FontFamily="{StaticResource FontFamilyTitle}"
                                   HorizontalAlignment="Left" 
                                   VerticalAlignment="Top" 
                                   Margin="0,0,0,0" />
                        <TextBlock Text="day(s) old" 
                                   FontSize="18" 
                                   HorizontalAlignment="Left" 
                                   VerticalAlignment="Top" />
                    </StackPanel>
                </Grid>
                <Grid Grid.Column="1" 
                      Margin="0,5,10,10">
                    <StackPanel HorizontalAlignment="Left" 
                                VerticalAlignment="Top">
                        <TextBlock Text="{Binding EmployeeName}" 
                                   FontSize="18" 
                                   TextWrapping="Wrap"
                                   HorizontalAlignment="Left" 
                                   VerticalAlignment="Center" />
                        <TextBlock Text="{Binding Purpose}" 
                                   FontSize="18" 
                                   Margin="0,10,0,0"
                                   TextWrapping="Wrap"
                                   HorizontalAlignment="Left" 
                                   VerticalAlignment="Center" />
                        <TextBlock Text="{Binding Amount, Converter={StaticResource DoubleToCurrencyStringConverter}}" 
                                   FontSize="18" 
                                   FontWeight="Bold" 
                                   Margin="0,10,0,0"
                                   HorizontalAlignment="Left" 
                                   VerticalAlignment="Center" />
                        <TextBlock Text="{Binding DateSubmitted, Converter={StaticResource DateTimeToStringConverter}}" 
                                   FontSize="18" 
                                   Margin="0,10,0,0" 
                                   HorizontalAlignment="Left" 
                                   VerticalAlignment="Center" />
                    </StackPanel>
                </Grid>
            </Grid>
        </DataTemplate>

        <DataTemplate x:Key="SnappedNeedingApprovalExpenseReportTemplate">
            <Grid Background="{StaticResource ItemTemplateBackgroundColor}"
                  Height="175">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="100"/>
                    <ColumnDefinition Width="160"/>
                </Grid.ColumnDefinitions>
                <Grid Grid.Column="0" 
                      Margin="10,5,0,5">
                    <StackPanel HorizontalAlignment="Left" 
                                VerticalAlignment="Top">
                        <TextBlock Text="{Binding DateSubmitted, Converter={StaticResource DateTimeToDaysOldStringConverter}}" 
                                   FontSize="28" 
                                   FontWeight="Bold" 
                                   FontFamily="{StaticResource FontFamilyTitle}"
                                   HorizontalAlignment="Left" 
                                   VerticalAlignment="Top" 
                                   Margin="0,0,0,0" />
                        <TextBlock Text="day(s) old" 
                                   FontSize="16" 
                                   HorizontalAlignment="Left" 
                                   VerticalAlignment="Top" />
                    </StackPanel>
                </Grid>
                <Grid Grid.Column="1" 
                      Margin="0,5,10,10">
                    <StackPanel HorizontalAlignment="Left" 
                                VerticalAlignment="Top">
                        <TextBlock Text="{Binding EmployeeName}" 
                                   FontSize="16" 
                                   TextWrapping="Wrap"
                                   HorizontalAlignment="Left" 
                                   VerticalAlignment="Center" />
                        <TextBlock Text="{Binding Purpose}" 
                                   FontSize="16" 
                                   Margin="0,10,0,0"
                                   TextWrapping="Wrap"
                                   HorizontalAlignment="Left" 
                                   VerticalAlignment="Center" />
                        <TextBlock Text="{Binding Amount, Converter={StaticResource DoubleToCurrencyStringConverter}}" 
                                   FontSize="16" 
                                   FontWeight="Bold" 
                                   Margin="0,10,0,0"
                                   HorizontalAlignment="Left" 
                                   VerticalAlignment="Center" />
                        <TextBlock Text="{Binding DateSubmitted, Converter={StaticResource DateTimeToStringConverter}}" 
                                   FontSize="16" 
                                   Margin="0,10,0,0" 
                                   HorizontalAlignment="Left" 
                                   VerticalAlignment="Center" />
                    </StackPanel>
                </Grid>
            </Grid>
        </DataTemplate>

    </Page.Resources>

    <Grid x:Name="LayoutRoot" 
          Background="{StaticResource AppBackgroundColor}">
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Border Background="{StaticResource ItemTemplateBackgroundColor}">
                <Button x:Name="BackButton" 
                        Click="BackButton_Click" 
                        Style="{StaticResource BackButtonStyle}"/>
            </Border>
            <Border Background="{StaticResource ItemTemplateBackgroundColor}"
                    Grid.Column="1" >
                <TextBlock x:Name="PageTitleTextBlock" 
                           Text="Charges"
                           Style="{StaticResource PageHeaderTextStyle}"
                           TextWrapping="Wrap"
                           FontSize="44"/>
            </Border>
        </Grid>

        <ProgressRing x:Name="ExpenseReportsProgressRing" 
                      Grid.Row="1" 
                      Height="150"
                      Width="150"
                      IsActive="False"/>

        <GridView x:Name="ExpenseReportsGridView"
                  Grid.Row="1"
                  Margin="120,50,0,0"
                  ItemsSource="{Binding Source={StaticResource ExpenseReportsViewSource}}"
                  ItemTemplate="{StaticResource SavedExpenseReportTemplate}"
                  SelectionMode="None"
                  IsSwipeEnabled="False"
                  IsItemClickEnabled="True"
                  ItemClick="ExpenseReportsGridView_ItemClick">
            <GridView.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapGrid Orientation="Vertical"/>
                </ItemsPanelTemplate>
            </GridView.ItemsPanel>
        </GridView>

        <ListView x:Name="ExpenseReportsListView"
                  AutomationProperties.AutomationId="ExpenseReportsListView"
                  AutomationProperties.Name="Grouped Items"
                  Grid.Row="1"
                  Width="300"
                  Visibility="Collapsed"
                  Margin="15,0,0,0"
                  ItemsSource="{Binding Source={StaticResource ExpenseReportsViewSource}}"
                  ItemTemplate="{StaticResource SnappedSavedExpenseReportTemplate}"
                  SelectionMode="None"
                  IsSwipeEnabled="False"
                  IsItemClickEnabled="True"
                  ItemClick="ExpenseReportsGridView_ItemClick">
        </ListView>

        <VisualStateManager.VisualStateGroups>

            <!-- Visual states reflect the application's view state -->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape"/>
                <VisualState x:Name="Filled"/>

                <!-- The entire page respects the narrower 100-pixel margin convention for portrait -->
                <VisualState x:Name="FullScreenPortrait">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PageTitleStackPanel" 
                                                       Storyboard.TargetProperty="Orientation">
                            <DiscreteObjectKeyFrame KeyTime="0" 
                                                    Value="Vertical"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ReportsSummaryTextBlock1" 
                                                       Storyboard.TargetProperty="Margin">
                            <DiscreteObjectKeyFrame KeyTime="0" 
                                                    Value="0,20,0,0"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ReportsSummaryTextBlock2" 
                                                       Storyboard.TargetProperty="Margin">
                            <DiscreteObjectKeyFrame KeyTime="0" 
                                                    Value="0,20,0,10"/>
                        </ObjectAnimationUsingKeyFrames>

                    </Storyboard>
                </VisualState>

                <!-- The back button and title have different styles when snapped -->
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackButton" 
                                                       Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" 
                                                    Value="{StaticResource SnappedBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PageTitleTextBlock" 
                                                       Storyboard.TargetProperty="FontSize">
                            <DiscreteObjectKeyFrame KeyTime="0" 
                                                    Value="20"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PageTitleTextBlock" 
                                                       Storyboard.TargetProperty="FontWeight">
                            <DiscreteObjectKeyFrame KeyTime="0" 
                                                    Value="SemiBold"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ExpenseReportsGridView" 
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" 
                                                    Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ExpenseReportsListView" 
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" 
                                                    Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ExpenseReportsListView" 
                                                       Storyboard.TargetProperty="Margin">
                            <DiscreteObjectKeyFrame KeyTime="0" 
                                                    Value="15,20,0,0"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</common:LayoutAwarePage>
